<template>
  <div id="app">
    <!-- <i class="iconfont icon-loading"></i> -->

    <TopBar :key="topbarKeyValue"></TopBar>
    <Header></Header>

    <router-view />
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Footer from "@/components/Footer.vue";
import Header from "@/components/Header.vue";
import TopBar from "@/components/TopBar.vue";
import Toast from "@/components/Toast.vue";
import Login from "@/components/Login";
import { mapState } from "vuex";

import { JingpinAPI } from "@/request/api";

export default {
  data() {
    return {
      topbarKeyValue: 0,
    };
  },
  components: {
    Footer,
    Header,
    TopBar,
    Login,
    Toast,
  },
  // async created() {
  //   let res = await JingpinAPI();
  //   console.log(res);
  // },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  watch: {
    //希望每次切换路由时，都让topbar重新加载（方式二）
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          this.topbarKeyValue++;
        }
      },
    },
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
